package de.jmda.gen.java.impl;

import static org.junit.Assert.assertTrue;

import org.apache.log4j.Logger;
import org.junit.Test;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.java.FieldDeclarationGenerator;

public class JUT_DefaultFieldDeclarationGenerator
{
	private final static Logger LOGGER =
      Logger.getLogger(JUT_DefaultFieldDeclarationGenerator.class);

	@Test
	public void testDefaultFieldDeclarationGenerator()
			throws GeneratorException
	{
		FieldDeclarationGenerator generator =
				new DefaultFieldDeclarationGenerator(
						new DefaultDeclaredInstanceFieldGenerator(
								new DefaultFieldModifiersGenerator(),
								new DefaultTypeNameGenerator(),
								new DefaultFieldNameGenerator(),
								new DefaultInitialisationGenerator()));

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected field declaration [" + generated + "]",
				"void field_name;".contentEquals(generated));
	}

	@Test
	public void testDefaultFieldDeclarationGeneratorWithJavaDoc()
			throws GeneratorException
	{
		String input1 = "test1";
		String input2 = "test2";

		FieldDeclarationGenerator generator =
				new DefaultFieldDeclarationGenerator(
						new DefaultDeclaredInstanceFieldGenerator(
								new DefaultFieldModifiersGenerator(),
								new DefaultTypeNameGenerator(),
								new DefaultFieldNameGenerator(),
								new DefaultInitialisationGenerator()));

		generator.setJavaDocGenerator(new DefaultJavaDocGenerator(input1, input2));

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected field declaration [" + generated + "]",
				(
						"/**"          + System.lineSeparator() +
						" * " + input1 + System.lineSeparator() +
						" * " + input2 + System.lineSeparator() +
						" */" +          System.lineSeparator() +
						"void field_name;"
				).contentEquals(generated));
	}
}